package com.dave.gd.core.common.globalsession.servlet;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dave.gd.core.common.globalsession.GlobalHttpSession;
import com.dave.gd.core.common.globalsession.manager.SessionManager;

@SuppressWarnings("serial")
public class ListSessionServlet extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html; charset=UTF-8";
    
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        // servlet方式输出页面
        // 设置页面字符集
        response.setContentType(CONTENT_TYPE);
        SessionManager sm = new SessionManager();
        Map<String, String> indexs = sm.getAllSessionIndex();
        request.setAttribute("indexs", indexs);
        request.setAttribute("counter", indexs.size());
        request.setAttribute("sessionid", request.getSession().getId());
        request.getRequestDispatcher("sessionManage.jsp").forward(request, response);
    }
    
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
        doGet(req, resp);
    }
    
    protected static boolean isGlobalSessionHttpRequest(HttpServletRequest req) {
        return req.getSession() instanceof GlobalHttpSession;
    }
    
}
